package com.zhiyou.app.shop.manager.action;

import org.springframework.beans.factory.annotation.Autowired;

import com.zhiyou.app.shop.common.BaseAction;
import com.zhiyou.app.shop.manager.dao.pojo.UserDetail;
import com.zhiyou.app.shop.manager.service.ISysManageService;

public class LoginAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private String userName;
	private String password;
	
	@Autowired
	private ISysManageService sysManageService;
	
	public String doLogin(){
		try {
			UserDetail user = sysManageService.loginAuth(userName, password);
			this.getRequest().getSession(false).setAttribute("user", user);
			if(user.getRole() == 0){
				return "admin";
			}else if(user.getRole() == 1){
				return "comManager";
			}else if(user.getRole() == 2){
				return "commonUser";
			}
			return SUCCESS;
		} catch (Exception e) {
			this.setErrorMessage(e);
		}
		return "login";
	}
	
	/**
	 * 退出登录
	 * @return
	 */
	public String doLogOut(){
		this.getRequest().getSession(false).removeAttribute("user");
		return "login";
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
}
